package com.patterns.chainOfResponsibility.wifelySubmission;

import java.util.ArrayList;
import java.util.Random;

/**
 * Created by Xiao Yiyun on 2017/4/28.
 * 场景类
 */
public class Client {
    public static void main(String[] args) {
        //通过随机数随机挑选出几名不同类型的女生
        Random random = new Random();
        ArrayList<IWomen> arrayList = new ArrayList<IWomen>();
        for (int i=0; i<10; i++) {
            arrayList.add(new Women(random.nextInt(4), "我要出去逛街"));
        }
        //定义三个请求对象，也就是处理者
        Handler father = new Father();
        Handler husband = new Husband();
        Handler son = new Son();
        //设置请求顺序，创建责任链
        father.setNextHandler(husband);
        husband.setNextHandler(son);
        son.setNextHandler(null);
        //通过循环每个女生开始从父亲那里进行请求
        //如果不是对应处理者，将按照责任链自动调到下一个
        //知道访问到对应的处理者，或者到链尾
        for (IWomen women:arrayList) {
            father.HandleMessage(women);
        }
    }
}
